"""
    链式队列
"""


# 队列异常
class QueueError(Exception):
    pass


class Node:
    def __init__(self, val, next=None):
        self.val = val
        self.next = next


class LinkQueue:
    def __init__(self):
        self.front = self.rear = Node(None)

    def is_empty(self):
        return self.front is self.rear

    def enqueue(self, elem):
        """
            入队
        :param elem:
        :return:
        """
        self.rear.next = Node(elem)
        self.rear = self.rear.next

    def dequeue(self):
        """
            出队
        :return:
        """
        if self.front == self.rear:
            raise QueueError('Queue is empty')

        self.front = self.front.next
        return self.front.val

    def clear(self):
        """
            清空队列
        :return:
        """
        self.front = self.rear


if __name__ == "__main__":
    lq = LinkQueue()
    print(lq.is_empty())
    lq.enqueue(10)
    lq.enqueue(20)
    lq.enqueue(30)
    while not lq.is_empty():
        print(lq.dequeue())
